package helm

import (
	"encoding/json"
	"gluenet/pkg/ops/impl/helm"
)

type Instance struct {
	Guid     string      `json:"name" yaml:"name"`
	Name     string      `json:"guid" yaml:"guid"`
	Config   interface{} `json:"config" yaml:"config"`
	Instance interface{} `json:"instance" yaml:"instance"`
}

func CreateInstanceFromConfig(cfgValues string, name, guid string) (string, error) {
	var (
		err      error
		instance = Instance{}
	)

	var cfg = helm.Result{}
	if err = json.Unmarshal([]byte(cfgValues), &cfg); err != nil {
		return "", err
	}

	instance.Config = cfg
	instance.Guid = guid
	instance.Name = name

	ins, _ := json.Marshal(instance)
	return string(ins), nil
}
